# _*_coding:utf-8 _*_
#@Time    :2020/4/1 14:37
#@Author  :Dapan
#@Email : wali666@qq.com
from tkinter import *
import wmi
import hashlib


def get_card_id():
    """
    获取本机主板 ID
    :return: 本机主板序列号
    """
    card_info = wmi.WMI()
    card_id = card_info.Win32_BaseBoard()[0].SerialNumber.strip()
    return card_id

def make_machine_code(card_id):
    """
    将主板序列号处理为机器码
    :return: 机器码
    """
    # MD5加密
    m = hashlib.md5(card_id.encode('utf-8'))
    md5_str = m.hexdigest()
    # 截取前12位
    machine_code = md5_str
    return machine_code


def main():
    card_id = get_card_id()
    machine_code = make_machine_code(card_id)
    root = Tk()
    root.title('复制机器码')
    root.geometry("300x100")
    content = StringVar()
    content.set(machine_code)
    e = Entry(root,
              textvariable=content,
              state='readonly',
              )
    e.pack(padx=10, pady=10)

    mainloop()


if __name__ == '__main__':
    main()
